<?php
/**
 * Created by PhpStorm.
 * User: SmartCodeTool
 * Date: {{date}}
 * Time: {{time}}
 */

namespace {{nameSpace}};

use app\common\lib\AdminController;
use app\common\lib\TpQuerySet;
use {{validateNameSpace}};
use {{serviceNameSpace}};
use {{dtoNameSpace}};
use think\Request;

/**
 * {{tableName}}
 * Class {{className}}
 * @package {{nameSpace}}
 */
class {{className}} extends AdminController
{
    /**
     * {{tableDesc}}列表
     * @param Request $request
     * @return \think\Response\Json
     */
    public function lists(Request $request)
    {
        $param = $request->param();
        $result = {{serviceClassName}}::getInstance()->lists(TpQuerySet::create(
            ['queryParam' => $param]
        ));
        return $this->json($result);
    }

    /**
     * {{tableDesc}}详情
     * @param Request $request
     * @return \think\Response\Json
     */
    public function detail(Request $request)
    {
        ${{pk}} = $request->param('{{pk}}');
        $result = {{serviceClassName}}::getInstance()->setSearchPrefix('')
            ->detail(TpQuerySet::create(
                ['where' => [['{{pk}}','=',${{pk}}]]]
            ));
        return $this->json($result);
    }


    /**
     * 创建{{tableDesc}}
     * @param Request $request
     * @return \think\Response\Json
     */
    public function create(Request $request)
    {
        {{validateClassName}}::getInstance()->goCheck();
        $result = {{serviceClassName}}::getInstance()->create(
            {{dtoClassName}}::create($request->param())
        );
        return $this->json(['id' => $result]);
    }

    /**
     * 编辑{{tableDesc}}
     * @param Request $request
     * @return \think\Response\Json
     */
    public function update(Request $request)
    {
        {{validateClassName}}::getInstance()->goCheck();
        $result = {{serviceClassName}}::getInstance()->update(
            {{dtoClassName}}::create($request->param())
        );
        return $this->json(['id' => $result]);
    }

    /**
     * 删除{{tableDesc}}
     * @param Request $request
     * @return \think\Response\Json
     */
    public function delete(Request $request)
    {
        {{serviceClassName}}::getInstance()->deleteIds();
        return $this->json(['msg' => '删除成功']);
    }
}